import rclpy
from rclpy.node import Node

from sensor_msgs.msg import Temperature


class DoublePublisher(Node):

    def __init__(self):
        super().__init__('double_publisher')

        # create publishers
        self.publisher_temp_1_ = self.create_publisher(Temperature, 'temp_1', 10)
        self.publisher_temp_2_ = self.create_publisher(Temperature, 'temp_2', 10)

        # create timer
        timer_period = 1 
        self.timer_ = self.create_timer(timer_period, self.timer_callback)

        # initialize counter
        self.i = 0

    def timer_callback(self):
        self.get_logger().info("Publishing messages")

        # get current time for headers
        msg_stamp = self._clock.now().to_msg()

        # create and publish Temperature messages
        msg_1 = Temperature()
        msg_1.header.stamp = msg_stamp
        msg_1.temperature = float(self.i)
        self.publisher_temp_1_.publish(msg_1)

        msg_2 = Temperature()
        msg_2.header.stamp = msg_stamp
        msg_2.temperature = float(self.i + 2)
        self.publisher_temp_2_.publish(msg_2)

        self.i += 1


def main(args=None):
    rclpy.init(args=args)

    minimal_publisher = DoublePublisher()

    rclpy.spin(minimal_publisher)

    minimal_publisher.destroy_node()
    rclpy.shutdown()


if __name__ == '__main__':
    main()